using System.Xml;

namespace Kotonoha.Server.Xml {
    public class AttributedHandler : ElementHandler {
        private readonly ElementAction action;
        private Element e;

        public AttributedHandler(string name, ElementAction act) : base(name) {
            this.action = act;
            OnStart += start;
        }

        protected override void readBody(XmlReader reader) {
            e.Content = reader.ReadString();
            action(e);
        }

        protected override void readAttributes(XmlReader reader) {
            while (reader.MoveToNextAttribute()) {
                e.Add(reader.Name, reader.Value);
            }
        }

        protected void start() {
            e = new Element();
        }
    }
}